//
//  XJMyOrderCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/26.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  我的订单cell

#import "XJMyOrderCell.h"
@interface XJMyOrderCell()
@property(nonatomic, strong) UIView *bgView; //习惯 <div>  </div>
@property(nonatomic, strong) UIImageView *iconIV;
@property(nonatomic, strong) UILabel *nameLabel; // 新款欧美甜美双层荷叶边小礼服惺惺惜惺惺想寻
@property(nonatomic, strong) UILabel *guigeLabel;// 套餐1:粉色
@property(nonatomic, strong) UILabel *priceLabel;// ￥399.00
@property(nonatomic, strong) UILabel *countLabel; // x1


@end

@implementation XJMyOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - 一 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)setupView {
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.iconIV];
    [self.bgView addSubview:self.nameLabel];
    [self.bgView addSubview:self.guigeLabel];
    [self.bgView addSubview:self.priceLabel];
    [self.bgView addSubview:self.countLabel];
}
#pragma mark - 二 lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
//        _bgView.backgroundColor = [UIColor redColor];
    }
    return _bgView;
}
- (UIImageView *)iconIV {
    if (!_iconIV) {
        _iconIV = [[UIImageView alloc] init];
        _iconIV.layer.masksToBounds = YES;
        _iconIV.layer.cornerRadius = 8;
    }
    return _iconIV;
}
- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.numberOfLines = 0;
    }
    return _nameLabel;
}
- (UILabel *)guigeLabel {
    if (!_guigeLabel) {
        _guigeLabel = [[UILabel alloc] init];
        _guigeLabel.font = XJFONTSET_R(14.0);
        _guigeLabel.textColor = XJCOLOR_RGB(110, 110, 110);
    }
    return _guigeLabel;
}
- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
    }
    return _priceLabel;
}
- (UILabel *)countLabel {
    if (!_countLabel) {
        _countLabel = [[UILabel alloc] init];
        _countLabel.font = XJFONTSET_R(14.0);
        _countLabel.textColor = XJCOLOR_RGB(110, 110, 110);
        _countLabel.textAlignment = NSTextAlignmentRight;
    }
    return _countLabel;
}

#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    // cell的高度应该为120;
    // h:100
    [self.iconIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(10);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    
    // 不给高度 自适应
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIV.mas_right).offset(5);
        make.top.equalTo(self.iconIV.mas_top);
        make.right.equalTo(self.bgView.mas_right).offset(-10);
    }];
 
    //h:15
    [self.guigeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(5);
        make.left.equalTo(self.iconIV.mas_right).offset(5);
        make.height.mas_equalTo(15);
        make.right.equalTo(self.nameLabel.mas_right);
    }];
    
    // h:20
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.guigeLabel.mas_bottom).offset(5);
        make.left.equalTo(self.iconIV.mas_right).offset(5);
        make.size.mas_equalTo(CGSizeMake(150, 20));
        make.bottom.equalTo(self.iconIV.mas_bottom);
    }];
    
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.priceLabel.mas_centerY);
        make.right.equalTo(self.nameLabel.mas_right);
        make.left.equalTo(self.priceLabel.mas_right).offset(30);
        make.height.mas_equalTo(15);
    }];
}


#pragma mark - 赋值
- (void)configureXJMyOrderCellWithImgStr:(NSString *)imgStr name:(NSString *)name price:(NSString *)price count:(NSString *)count {
    
    UIImage *defaultimg = [UIImage imageNamed:@"default_goods"];
    [self.iconIV sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:defaultimg];
    
    self.nameLabel.text = name;
    
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f",[price floatValue]];
    
    self.countLabel.text = [NSString stringWithFormat:@"x%@",count];
}




@end
